/**
 * Project Name yh-appms
 * File Name SwaggerConfig
 * Package Name cn.csg.ys.data.server.config
 * Create Time 2019/5/29
 * Create by name：liujie -- email: jie_liu1@asdc.com.cn
 * Copyright © 2015, 2018, www.asdc.com.cn. All rights reserved.
 */
package com.yzp.config;

import io.swagger.models.Contact;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Description
 *
 * @ClassName: SwaggerConfig
 * @author: Yzp
 * @date: 2019/5/29 16:24
 */
@Configuration
@EnableSwagger2
//@ConditionalOnProperty(name = "swagger.enable", havingValue = "true")
public class SwaggerConfig {
    private final static String SWAGGER_SCAN_BASE_PACKAGE = "com.yzp.controller";
    private final static String VERSION = "1.0.0";

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //api接口包扫描路径
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
                //可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .paths(PathSelectors.any())
                .build();
    }
    private ApiInfo apiInfo() {
        final ApiInfo build = new ApiInfoBuilder()
                //设置文档的标题
                .title("数据服务接口文档")
                //设置文档的描述->1.Overview
                .description("更多内容请关注：http://www.yzp.top")
                //设置文档的版本信息-> 1.1 Version information
                .version(VERSION)
                //设置文档的联系方式->1.2 Contact information
                .contact(build())
                //设置文档的License信息->1.3 License information
                .termsOfServiceUrl("http://www.yzp.top")
                .build();
        return build;
    }
    protected String build(){
        Contact contact = new Contact();
        contact.setEmail("7448043@qq.com");
        contact.setUrl("http://www.yzp.top");
        contact.setName("white");
        return contact.toString();
    }
}
